package member.model;

import java.util.Date;
import java.util.HashMap;
import java.util.HashSet;
import java.util.Map;
import java.util.Set;

import javax.persistence.*;

import org.apache.commons.logging.Log;
import org.apache.commons.logging.LogFactory;

/**
 * <p>
 * This component and its source code representation are copyright protected and
 * proprietary to The Trivera Group, Inc., Worldwide D/B/A Trivera Technologies
 *
 * This component and source code may be used for instructional and evaluation
 * purposes only. No part of this component or its source code may be sold,
 * transferred, or publicly posted, nor may it be used in a commercial or
 * production environment, without the express written consent of the Trivera
 * Group, Inc.
 *
 * Copyright (c) 2015 The Trivera Group, LLC. http://www.triveratech.com
 * http://www.triveragroup.com
 * </p>
 * 
 * @author The Trivera Group Tech Team.
 */

@Entity
@Table(schema = "DVDRental")
public class Member {
	private static final Log log = LogFactory.getLog(Member.class);

	@Id
	@GeneratedValue(strategy = GenerationType.IDENTITY)
	@Column(name = "MEMBER_ID")
	private int id;
	@Column(name = "USERNAME", unique = true)
	private String username;
	private String email;
	private Date memberSinceDate;
	private Boolean active;
	
	@CollectionTable(name="Address", schema="DVDRental", 
			joinColumns = @JoinColumn(name="Member_ID"))
	@MapKeyColumn(name="TYPE")
	@ElementCollection(fetch=FetchType.EAGER)
	private Map<String, Address> addresses;
	
	@CollectionTable(name="REVIEWS", schema="DVDRental",
			joinColumns= @JoinColumn(name="Member_ID"))
	@ElementCollection
	@Column(name="REVIEW")
	private Set<String> reviews;
		
	protected Member() {
		this(null);
	}

	public Member(String userName) {
		this.username = userName;
		addresses = new HashMap<>();
		reviews = new HashSet<>();
	}

	public void addAddress (String type, Address addr)
	{
		addresses.put(type, addr);
	}
	public void addReview(String review)
	{
		reviews.add(review);
	}
	
	
	public Map<String, Address> getAddresses() {
		return addresses;
	}

	public void setAddresses(Map<String, Address> addresses) {
		this.addresses = addresses;
	}

	public int getId() {
		return id;
	}

	public void setId(int id) {
		this.id = id;
	}

	public String getUsername() {
		return username;
	}

	public void setUsername(String username) {
		this.username = username;
	}

	public String getEmail() {
		return email;
	}

	public void setEmail(String email) {
		this.email = email;
	}

	public Date getMemberSinceDate() {
		return memberSinceDate;
	}

	public void setMemberSinceDate(Date memberSinceDate) {
		this.memberSinceDate = memberSinceDate;
	}

	public Boolean getActive() {
		return active;
	}

	public void setActive(Boolean active) {
		this.active = active;
	}

	@Override
	public String toString() {
		return "Member [id=" + id + ", username=" + username + ", email="
				+ email + ", memberSinceDate=" + memberSinceDate + ", active="
				+ active + ", addresses=" +  ", reviews=" + reviews
				+ "]";
	}

	
	

	

	

}
